package ch.bfh.ti.barcode.colorQrCode;

import com.google.zxing.LuminanceSource;

/**
 * This LuminanceSource doesn't do anything. It replaces the RGBLuminanceSource
 * for performance reasons.
 * 
 * @author Dominik von Burg
 * 
 */
public class SimpleLuminanceSource extends LuminanceSource {
	private byte[] data;

	/**
	 * Creates a new Luminance source with the given width and height.
	 * 
	 * @param width
	 *            The width of the luminance source.
	 * @param height
	 *            The height of the luminance source.
	 */
	protected SimpleLuminanceSource(int width, int height) {
		super(width, height);
	}

	/**
	 * Creates a new luminance source with the given width and height and sets
	 * the data.
	 * 
	 * @param width
	 *            The width of the luminance source.
	 * @param height
	 *            The height of the luminance source.
	 * @param data
	 *            The data of the luminance source. This data is read from the
	 *            "Binarizer" without any modifications.
	 */
	public SimpleLuminanceSource(int width, int height, byte[] data) {
		super(width, height);
		this.data = data;
	}

	@Override
	public byte[] getMatrix() {
		return data;
	}

	@Override
	public byte[] getRow(int row, byte[] rowData) {
		int width = getWidth();

		if (rowData == null || rowData.length < width)
			rowData = new byte[width];

		System.arraycopy(data, row * width, rowData, 0, width);
		return rowData;
	}
}
